﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.WebComponent
Imports AugmentLib.InputOutput.Encryption

Partial Class UploadSearch
    Inherits System.Web.UI.Page

#Region " Properties "

    Public Property CurrentPage() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPage As Object = ViewState("_CurrentPage")
            If objPage Is Nothing Then
                Return 0
            Else
                'default to showing the first page
                Return CInt(objPage)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_CurrentPage") = value
        End Set
    End Property

    Public Property PageSize() As Integer
        Get
            'Looks for the current page in ViewState
            Dim objPageSize As Object = ViewState("_PageSize")
            If objPageSize Is Nothing Then
                Return 25
            Else
                'default to showing the first page
                Return CInt(objPageSize)
            End If
        End Get
        Set(ByVal value As Integer)
            ViewState("_PageSize") = value
        End Set
    End Property

#End Region

#Region " Paging and Page Size "

    Protected Sub lnkHead10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead10Item.Click
        PageSize = 10
        LoadUpload()
    End Sub

    Protected Sub lnkHead25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead25Item.Click
        PageSize = 25
        LoadUpload()
    End Sub

    Protected Sub lnkHead100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead100Item.Click
        PageSize = 100
        LoadUpload()
    End Sub

    Protected Sub lnkHead150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkHead150Item.Click
        PageSize = 150
        LoadUpload()
    End Sub

    Protected Sub lnkFoot10Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot10Item.Click
        PageSize = 10
        LoadUpload()
    End Sub

    Protected Sub lnkFoot25Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot25Item.Click
        PageSize = 25
        LoadUpload()
    End Sub

    Protected Sub lnkFoot100Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot100Item.Click
        PageSize = 100
        LoadUpload()
    End Sub

    Protected Sub lnkFoot150Item_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkFoot150Item.Click
        PageSize = 150
        LoadUpload()
    End Sub

    Protected Sub btnMoveFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveFirst.Click
        CurrentPage = 0
        txtPageNo.Text = CurrentPage + 1
        LoadUpload()
    End Sub

    Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        If CurrentPage > 0 Then
            CurrentPage = CurrentPage - 1
            txtPageNo.Text = CurrentPage + 1
            LoadUpload()
        End If
    End Sub

    Protected Sub btnGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGo.Click
        If CInt(txtPageNo.Text < 1) Then
            txtPageNo.Text = 1
        End If

        If CInt(txtPageNo.Text > CInt(lblMaxPageCount.Text)) Then
            txtPageNo.Text = CInt(lblMaxPageCount.Text) + 1
        End If

        CurrentPage = CInt(txtPageNo.Text) - 1
        LoadUpload()

    End Sub

    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If CurrentPage < CInt(lblMaxPageCount.Text) Then
            CurrentPage = CurrentPage + 1
            txtPageNo.Text = CurrentPage + 1
            LoadUpload()
        End If
    End Sub

    Protected Sub btnMoveLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMoveLast.Click
        CurrentPage = CInt(lblMaxPageCount.Text)
        txtPageNo.Text = CurrentPage + 1
        LoadUpload()
    End Sub

#End Region

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Session("anchor1") = ""
        LoadUpload()
    End Sub

    Private Sub LoadUpload()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        Dim Daerah, Mukim, Sek, JenisLot, NoLot, JenisHartanah, Alamat, Kawasan, Pemberi, Penerima, Balasan, LuasLot, TkhPenilaian, TkhPenilaian2 As String

        If txtDaerah.Text <> String.Empty Then
            Daerah = " AND Daerah LIKE @Daerah"
            objDB.AddParameter("Daerah", Data.SqlDbType.NVarChar, "%" & txtDaerah.Text.Trim & "%")
        Else
            daerah = String.Empty
        End If

        If txtMukim.Text <> String.Empty Then
            Mukim = " AND Mukim LIKE @Mukim"
            objDB.AddParameter("Mukim", Data.SqlDbType.NVarChar, "%" & txtMukim.Text.Trim & "%")
        Else
            Mukim = String.Empty
        End If

        If txtSek.Text <> String.Empty Then
            Sek = " AND Sek LIKE @Sek"
            objDB.AddParameter("Sek", Data.SqlDbType.NVarChar, "%" & txtSek.Text.Trim & "%")
        Else
            Sek = String.Empty
        End If

        If txtJenisLot.Text <> String.Empty Then
            JenisLot = " AND JenisLot LIKE @JenisLot"
            objDB.AddParameter("JenisLot", Data.SqlDbType.NVarChar, "%" & txtJenisLot.Text.Trim & "%")
        Else
            JenisLot = String.Empty
        End If

        If txtNoLot.Text <> String.Empty Then
            NoLot = " AND NoLot LIKE @NoLot"
            objDB.AddParameter("NoLot", Data.SqlDbType.NVarChar, "%" & txtNoLot.Text.Trim & "%")
        Else
            NoLot = String.Empty
        End If

        If txtJenisHartanah.Text <> String.Empty Then
            JenisHartanah = " AND JenisHartanah LIKE @JenisHartanah"
            objDB.AddParameter("JenisHartanah", Data.SqlDbType.NVarChar, "%" & txtJenisHartanah.Text.Trim & "%")
        Else
            JenisHartanah = String.Empty
        End If

        If txtAlamat.Text <> String.Empty Then
            'Alamat = " AND Alamat LIKE @Alamat"
            'objDB.AddParameter("Alamat", Data.SqlDbType.NVarChar, "%" & txtAlamat.Text.Trim & "%")
            Alamat = " AND Alamat LIKE '%" + txtAlamat.Text.Trim.Replace(",", "%' AND [Alamat] LIKE '%") + "%'"
        Else
            Alamat = String.Empty
        End If

        If txtKawasan.Text <> String.Empty Then
            'Kawasan = " AND Kawasan LIKE @Kawasan"
            'objDB.AddParameter("Kawasan", Data.SqlDbType.NVarChar, "%" & txtKawasan.Text.Trim & "%")
            Kawasan = " AND Kawasan LIKE '%" + txtKawasan.Text.Trim.Replace(",", "%' AND [Kawasan] LIKE '%") + "%'"
        Else
            Kawasan = String.Empty
        End If

        If txtPemberi.Text <> String.Empty Then
            Pemberi = " AND Pemberi LIKE @Pemberi"
            objDB.AddParameter("Pemberi", Data.SqlDbType.NVarChar, "%" & txtPemberi.Text.Trim & "%")
        Else
            Pemberi = String.Empty
        End If

        If txtPenerima.Text <> String.Empty Then
            Penerima = " AND Penerima LIKE @Penerima"
            objDB.AddParameter("Penerima", Data.SqlDbType.NVarChar, "%" & txtPenerima.Text.Trim & "%")
        Else
            Penerima = String.Empty
        End If

        If txtBalasanFrom.Text <> String.Empty And txtBalasanTo.Text <> String.Empty Then
            If CDbl(txtBalasanTo.Text) < CDbl(txtBalasanFrom.Text) Then
                Balasan = " AND Balasan BETWEEN @BalasanTo AND @BalasanFrom"
            Else
                Balasan = " AND Balasan BETWEEN @BalasanFrom AND @BalasanTo"
            End If
            objDB.AddParameter("BalasanTo", Data.SqlDbType.Decimal, CDbl(txtBalasanTo.Text.Trim))
            objDB.AddParameter("BalasanFrom", Data.SqlDbType.Decimal, CDbl(txtBalasanFrom.Text.Trim))
        Else
            If txtBalasanFrom.Text <> String.Empty Then
                If CDbl(txtBalasanFrom.Text) > 0 Then
                    Balasan = " AND Balasan=@BalasanFrom"
                    objDB.AddParameter("BalasanFrom", Data.SqlDbType.Decimal, CDbl(txtBalasanFrom.Text.Trim))
                End If
            ElseIf txtBalasanTo.Text <> String.Empty Then
                If CDbl(txtBalasanTo.Text) > 0 Then
                    Balasan = " AND Balasan=@BalasanTo"
                    objDB.AddParameter("BalasanTo", Data.SqlDbType.Decimal, CDbl(txtBalasanTo.Text.Trim))
                End If
            Else
                Balasan = String.Empty
            End If
        End If

        If txtLuasLot.Text <> String.Empty Then
            LuasLot = " AND LuasLot=@LuasLot"
            objDB.AddParameter("LuasLot", Data.SqlDbType.Decimal, CDbl(txtLuasLot.Text.Trim))
        Else
            LuasLot = String.Empty
        End If

        If txtTkhPenilaian.Text <> String.Empty Or txtTkhPenilaian2.Text <> String.Empty Then
            TkhPenilaian = " AND TkhPenilaian BETWEEN @DateFrom and @DateTo "
            If txtTkhPenilaian.Text <> String.Empty And txtTkhPenilaian2.Text.Trim() = String.Empty Then
                'TkhPenilaian = "AND TkhPenilaian=@TkhPenilaian"
                objDB.AddParameter("DateFrom", Data.SqlDbType.DateTime, DateTime.ParseExact(txtTkhPenilaian.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("DateTo", Data.SqlDbType.DateTime, DateTime.ParseExact(Date.Now, "dd-MMM-yyyy", Nothing))
            ElseIf txtTkhPenilaian.Text = String.Empty And txtTkhPenilaian2.Text.Trim() <> String.Empty Then
                objDB.AddParameter("DateFrom", Data.SqlDbType.DateTime, DateTime.ParseExact(Date.Now, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("DateTo", Data.SqlDbType.DateTime, DateTime.ParseExact(txtTkhPenilaian2.Text, "dd-MMM-yyyy", Nothing))
            Else  'Both not empty
                objDB.AddParameter("DateFrom", Data.SqlDbType.DateTime, DateTime.ParseExact(txtTkhPenilaian.Text, "dd-MMM-yyyy", Nothing))
                objDB.AddParameter("DateTo", Data.SqlDbType.DateTime, DateTime.ParseExact(txtTkhPenilaian2.Text, "dd-MMM-yyyy", Nothing))
            End If
        Else
            TkhPenilaian = String.Empty
        End If

            objDB.dbVariable.SQLString = "SELECT AucId, Daerah, Mukim, Sek, JenisLot, NoLot, TkhPenilaian, LuasLot, " & _
                                        "JenisHartanah, Alamat, Kawasan, Pemberi, Penerima, Balasan, CreateDate FROM " & _
                                        "AW_Auction WHERE StatusDelete=0" & Daerah & Mukim & Sek & JenisLot & NoLot & _
                                        TkhPenilaian & LuasLot & JenisHartanah & Alamat & Kawasan & Pemberi & Penerima & _
                                        Balasan & lblhidSortType.Text
            objDB.FillData(TempDT, "AW_Auction", Database.SQLCommandType.NormalString)

            objDB.CloseConnection()

            'Creating a Paged Datasouce
            Dim objPaged As New PagedDataSource
            objPaged.DataSource = TempDT.DefaultView
            objPaged.AllowPaging = True
            objPaged.PageSize = PageSize
            objPaged.CurrentPageIndex = CurrentPage

            lblHeadNoOfItem.Text = TempDT.Rows.Count
            lblFootNoOfItem.Text = TempDT.Rows.Count

            repUpload.DataSource = objPaged
            repUpload.DataBind()

            lblMaxPageCount.Text = objPaged.PageCount - 1
            lblTotalPage.Text = " of " & objPaged.PageCount
    End Sub

    Private Function SortType(ByVal strSortType As String) As String
        Dim strSort As String
        If Right(strSortType, 1) = "▼" Then
            strSort = "ASC"
        Else
            strSort = "DESC"
        End If
        Return strSort
    End Function

    Protected Sub lnkCreateDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkCreateDate.Click
        If lnkCreateDate.Text = "Create Date▼" Then
            lnkCreateDate.Text = "Create Date▲"
        Else
            lnkCreateDate.Text = "Create Date▼"
        End If

        lblhidSortType.Text = " ORDER BY CreateDate " & SortType(lnkCreateDate.Text) & _
                            ", Daerah " & SortType(lnkDaerah.Text) & ", Mukim " & SortType(lnkMukim.Text) & _
                            ", Sek " & SortType(lnkSek.Text) & ", JenisLot " & SortType(lnkJenisLot.Text) & _
                            ", NoLot " & SortType(lnkNoLot.Text) & ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & _
                            ", LuasLot " & SortType(lnkLuasLot.Text) & ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & _
                            ", Alamat " & SortType(lnkAlamat.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkDaerah_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkDaerah.Click
        If lnkDaerah.Text = "Daerah▼" Then
            lnkDaerah.Text = "Daerah▲"
        Else
            lnkDaerah.Text = "Daerah▼"
        End If

        lblhidSortType.Text = " ORDER BY Daerah " & SortType(lnkDaerah.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Mukim " & SortType(lnkMukim.Text) & _
                            ", Sek " & SortType(lnkSek.Text) & ", JenisLot " & SortType(lnkJenisLot.Text) & _
                            ", NoLot " & SortType(lnkNoLot.Text) & ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & _
                            ", LuasLot " & SortType(lnkLuasLot.Text) & ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & _
                            ", Alamat " & SortType(lnkAlamat.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkMukim_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkMukim.Click
        If lnkMukim.Text = "Mukim/Bandar▼" Then
            lnkMukim.Text = "Mukim/Bandar▲"
        Else
            lnkMukim.Text = "Mukim/Bandar▼"
        End If

        lblhidSortType.Text = " ORDER BY Mukim " & SortType(lnkMukim.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Sek " & SortType(lnkSek.Text) & ", JenisLot " & SortType(lnkJenisLot.Text) & _
                            ", NoLot " & SortType(lnkNoLot.Text) & ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & _
                            ", LuasLot " & SortType(lnkLuasLot.Text) & ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & _
                            ", Alamat " & SortType(lnkAlamat.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkSek_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSek.Click
        If lnkSek.Text = "Sek▼" Then
            lnkSek.Text = "Sek▲"
        Else
            lnkSek.Text = "Sek▼"
        End If

        lblhidSortType.Text = " ORDER BY Sek " & SortType(lnkSek.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", JenisLot " & SortType(lnkJenisLot.Text) & _
                            ", NoLot " & SortType(lnkNoLot.Text) & ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & _
                            ", LuasLot " & SortType(lnkLuasLot.Text) & ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & _
                            ", Alamat " & SortType(lnkAlamat.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkJenisLot_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkJenisLot.Click
        If lnkJenisLot.Text = "Jenis Lot/Plot▼" Then
            lnkJenisLot.Text = "Jenis Lot/Plot▲"
        Else
            lnkJenisLot.Text = "Jenis Lot/Plot▼"
        End If

        lblhidSortType.Text = " ORDER BY JenisLot " & SortType(lnkJenisLot.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", NoLot " & SortType(lnkNoLot.Text) & ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & _
                            ", LuasLot " & SortType(lnkLuasLot.Text) & ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & _
                            ", Alamat " & SortType(lnkAlamat.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkNoLot_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkNoLot.Click
        If lnkNoLot.Text = "No Lot/Plot▼" Then
            lnkNoLot.Text = "No Lot/Plot▲"
        Else
            lnkNoLot.Text = "No Lot/Plot▼"
        End If

        lblhidSortType.Text = " ORDER BY NoLot " & SortType(lnkNoLot.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", JenisLot " & SortType(lnkJenisLot.Text) & ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & _
                            ", LuasLot " & SortType(lnkLuasLot.Text) & ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & _
                            ", Alamat " & SortType(lnkAlamat.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkTkhPenilaian_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkTkhPenilaian.Click
        If lnkTkhPenilaian.Text = "Trkh Penilaian▼" Then
            lnkTkhPenilaian.Text = "Trkh Penilaian▲"
        Else
            lnkTkhPenilaian.Text = "Trkh Penilaian▼"
        End If

        lblhidSortType.Text = " ORDER BY TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", JenisLot " & SortType(lnkJenisLot.Text) & ", NoLot " & SortType(lnkNoLot.Text) & _
                            ", LuasLot " & SortType(lnkLuasLot.Text) & ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & _
                            ", Alamat " & SortType(lnkAlamat.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkLuasLot_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkLuasLot.Click
        If lnkLuasLot.Text = "Luas Lot▼" Then
            lnkLuasLot.Text = "Luas Lot▲"
        Else
            lnkLuasLot.Text = "Luas Lot▼"
        End If

        lblhidSortType.Text = " ORDER BY LuasLot " & SortType(lnkLuasLot.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", JenisLot " & SortType(lnkJenisLot.Text) & ", NoLot " & SortType(lnkNoLot.Text) & _
                            ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & _
                            ", Alamat " & SortType(lnkAlamat.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkJenisHartanah_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkJenisHartanah.Click
        If lnkJenisHartanah.Text = "Jenis Hartanah▼" Then
            lnkJenisHartanah.Text = "Jenis Hartanah▲"
        Else
            lnkJenisHartanah.Text = "Jenis Hartanah▼"
        End If

        lblhidSortType.Text = " ORDER BY JenisHartanah " & SortType(lnkJenisHartanah.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", JenisLot " & SortType(lnkJenisLot.Text) & ", NoLot " & SortType(lnkNoLot.Text) & _
                            ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & ", LuasLot " & SortType(lnkLuasLot.Text) & _
                            ", Alamat " & SortType(lnkAlamat.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkAlamat_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkAlamat.Click
        If lnkAlamat.Text = "Alamat▼" Then
            lnkAlamat.Text = "Alamat▲"
        Else
            lnkAlamat.Text = "Alamat▼"
        End If

        lblhidSortType.Text = " ORDER BY Alamat " & SortType(lnkAlamat.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", JenisLot " & SortType(lnkJenisLot.Text) & ", NoLot " & SortType(lnkNoLot.Text) & _
                            ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & ", LuasLot " & SortType(lnkLuasLot.Text) & _
                            ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & ", Kawasan " & SortType(lnkKawasan.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkKawasan_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkKawasan.Click
        If lnkKawasan.Text = "Kawasan▼" Then
            lnkKawasan.Text = "Kawasan▲"
        Else
            lnkKawasan.Text = "Kawasan▼"
        End If

        lblhidSortType.Text = " ORDER BY Kawasan " & SortType(lnkKawasan.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", JenisLot " & SortType(lnkJenisLot.Text) & ", NoLot " & SortType(lnkNoLot.Text) & _
                            ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & ", LuasLot " & SortType(lnkLuasLot.Text) & _
                            ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & ", Alamat " & SortType(lnkAlamat.Text) & _
                            ", Pemberi " & SortType(lnkPemberi.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkPemberi_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkPemberi.Click
        If lnkPemberi.Text = "Pemberi▼" Then
            lnkPemberi.Text = "Pemberi▲"
        Else
            lnkPemberi.Text = "Pemberi▼"
        End If

        lblhidSortType.Text = " ORDER BY Pemberi " & SortType(lnkPemberi.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", JenisLot " & SortType(lnkJenisLot.Text) & ", NoLot " & SortType(lnkNoLot.Text) & _
                            ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & ", LuasLot " & SortType(lnkLuasLot.Text) & _
                            ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & ", Alamat " & SortType(lnkAlamat.Text) & _
                            ", Kawasan " & SortType(lnkKawasan.Text) & ", Penerima " & SortType(lnkPenerima.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkPenerima_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkPenerima.Click
        If lnkPenerima.Text = "Penerima▼" Then
            lnkPenerima.Text = "Penerima▲"
        Else
            lnkPenerima.Text = "Penerima▼"
        End If

        lblhidSortType.Text = " ORDER BY Penerima " & SortType(lnkPenerima.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", JenisLot " & SortType(lnkJenisLot.Text) & ", NoLot " & SortType(lnkNoLot.Text) & _
                            ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & ", LuasLot " & SortType(lnkLuasLot.Text) & _
                            ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & ", Alamat " & SortType(lnkAlamat.Text) & _
                            ", Kawasan " & SortType(lnkKawasan.Text) & ", Pemberi " & SortType(lnkPemberi.Text) & _
                            ", Balasan " & SortType(lnkBalasan.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub lnkBalasan_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBalasan.Click
        If lnkBalasan.Text = "Balasan▼" Then
            lnkBalasan.Text = "Balasan▲"
        Else
            lnkBalasan.Text = "Balasan▼"
        End If

        lblhidSortType.Text = " ORDER BY Balasan " & SortType(lnkBalasan.Text) & _
                            ", CreateDate " & SortType(lnkCreateDate.Text) & ", Daerah " & SortType(lnkDaerah.Text) & _
                            ", Mukim " & SortType(lnkMukim.Text) & ", Sek " & SortType(lnkSek.Text) & _
                            ", JenisLot " & SortType(lnkJenisLot.Text) & ", NoLot " & SortType(lnkNoLot.Text) & _
                            ", TkhPenilaian " & SortType(lnkTkhPenilaian.Text) & ", LuasLot " & SortType(lnkLuasLot.Text) & _
                            ", JenisHartanah " & SortType(lnkJenisHartanah.Text) & ", Alamat " & SortType(lnkAlamat.Text) & _
                            ", Kawasan " & SortType(lnkKawasan.Text) & ", Pemberi " & SortType(lnkPemberi.Text) & _
                            ", Penerima " & SortType(lnkPenerima.Text)
        btnSearch_Click(sender, e)
    End Sub

    Protected Sub repUpload_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repUpload.ItemCommand
        If e.CommandName = "ViewList" Then
            'Edited by minginn - To allow user to go back to the search page with same search selection
            '1-Back Page
            '2-Page Size
            '3-Current Page
            '4-Daerah
            '5-Mukim
            '6-Sek
            '7-Jenis Lot
            '8-No Lot
            '9-Trkh Penilaian
            '10-Luas Lot
            '11-Jenis Hartanah
            '12-Alamat
            '13-Kawasan
            '14-Pemberi
            '15-Penerima
            '16-Balasan From
            '17-Balasan To      
            Dim strBack As String
            strBack = "UploadSearch.aspx" & "ڡ" & PageSize & "ڡ" & CurrentPage & "ڡ" & txtDaerah.Text.Trim & "ڡ" & _
                    txtMukim.Text.Trim & "ڡ" & txtSek.Text.Trim & "ڡ" & txtJenisLot.Text.Trim & "ڡ" & txtNoLot.Text.Trim & "ڡ" & _
                    txtTkhPenilaian.Text.Trim & "ڡ" & txtLuasLot.Text.Trim & "ڡ" & txtJenisHartanah.Text.Trim & "ڡ" & txtAlamat.Text.Trim & _
                    "ڡ" & txtKawasan.Text.Trim & "ڡ" & txtPemberi.Text.Trim & "ڡ" & txtPenerima.Text.Trim & "ڡ" & txtBalasanFrom.Text.Trim & _
                    "ڡ" & txtBalasanTo.Text.Trim
            Session.Add("Back", strBack)
            Session.Add("anchor1", e.CommandArgument)
            Response.Redirect("UploadView.aspx?id=" & SymmetricEncryptToHex(e.CommandArgument, "augment"))
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Session.Item("StaffId") Is Nothing Then
            Response.Redirect("default.aspx")
        End If

        'Edited by minginn @ 27/6/2011 - to load the same search when user back from other page
        If Not Session("Back") Is Nothing Then
            Dim strBack As String = Session("Back").ToString
            Dim arr() As String = strBack.Split("ڡ")
            '1-Back Page
            '2-Page Size
            '3-Current Page
            '4-Daerah
            '5-Mukim
            '6-Sek
            '7-Jenis Lot
            '8-No Lot
            '9-Trkh Penilaian
            '10-Luas Lot
            '11-Jenis Hartanah
            '12-Alamat
            '13-Kawasan
            '14-Pemberi
            '15-Penerima
            '16-Balasan From
            '17-Balasan To
            If arr(0).ToString.Contains("UploadSearch.aspx") Then
                PageSize = CInt(arr(1).ToString)
                CurrentPage = CInt(arr(2).ToString)
                txtDaerah.Text = arr(3).ToString
                txtMukim.Text = arr(4).ToString
                txtSek.Text = arr(5).ToString
                txtJenisLot.Text = arr(6).ToString
                txtNoLot.Text = arr(7).ToString
                txtTkhPenilaian.Text = arr(8).ToString
                txtLuasLot.Text = arr(9).ToString
                txtJenisHartanah.Text = arr(10).ToString
                txtAlamat.Text = arr(11).ToString
                txtKawasan.Text = arr(12).ToString
                txtPemberi.Text = arr(13).ToString
                txtPenerima.Text = arr(14).ToString
                txtBalasanFrom.Text = arr(15).ToString
                txtBalasanTo.Text = arr(16).ToString
                Session.Remove("Back")
                LoadUpload()
            Else
                Session.Remove("Back")
            End If
           
        End If

        If Not Page.IsPostBack Then

            lblStaffUID.Text = Session.Item("StaffId").ToString
            lblStaffType.Text = Session.Item("StaffType").ToString

        End If
    End Sub

    Protected Sub btnResetSearchFilter_Click(sender As Object, e As EventArgs) Handles btnResetSearchFilter.Click
        txtDaerah.Text = ""
        txtMukim.Text = ""
        txtAlamat.Text = ""
        txtBalasanFrom.Text = ""
        txtBalasanTo.Text = ""
        txtDaerah.Text = ""
        txtJenisHartanah.Text = ""
        txtJenisLot.Text = ""
        txtKawasan.Text = ""
        txtLuasLot.Text = ""
        txtMukim.Text = ""
        txtNoLot.Text = ""
        txtPemberi.Text = ""
        txtPenerima.Text = ""
        txtSek.Text = ""
        txtTkhPenilaian.Text = ""
        txtTkhPenilaian2.Text = ""
    End Sub
End Class
